home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 117 / MacAddict 117.dmg / Software / Internet & Communication / Snak 5.1 (shareware).dmg / Snak.app / Contents / Resources / Scripts / TriviaBot / Trivia version 1.1.0 / trivia.txt < prev   
Text File  |  2005-03-14  |  70KB  |  2,333 lines

  1. # IRCII Trivia Script v1.1.0
  2. # Copyright (c) 2001-2002 Bernard Yen (Seeker on IRC)
  3.  
  4. # --------------------------------------------------------------------------
  5. # This software is provided 'as-is', without any expressed or implied
  6. # warrenty. In no event will the author be held liable for any damages
  7. # arising from the use of this software.
  8. #
  9. # Permissing is granted to anyone to use this software for non-commercial
  10. # purposes and to alter and redistribute it freely, subject to the
  11. # following restrictions:
  12. #
  13. # 1. The origin of this software must not be misrepresented; you must not
  14. # claim that you wrote the original software. If you use this software in
  15. # a product, an acknowledgement in the product documentation is required.
  16. #
  17. # 2. Altered source versions must be plainly marked as such, and must not
  18. # be misrepresented as being the original software
  19. #
  20. # 3. This notice may not be removed or altered from any source distribution.
  21. # --------------------------------------------------------------------------
  22.  
  23. # --- Program Constant Declarations ---
  24.  
  25. # Limit on how long each question is posed for in seconds
  26.  
  27. @trivia.LIMIT.1 = 50
  28. @trivia.LIMIT.2 = 50
  29. @trivia.LIMIT.3 = 45
  30. @trivia.LIMIT.4 = 45
  31. @trivia.LIMIT.5 = 40
  32.  
  33. # Number of seconds to pause between questions
  34.  
  35. @trivia.BREAK = 20
  36.  
  37. # Number of seconds before a duel is called off
  38.  
  39. @trivia.DUELSTOPTIME = 30
  40.  
  41. # Level of duelling question to ask
  42.  
  43. @trivia.DUELLEVEL = 3
  44.  
  45. # Number of seconds to wait before a duel is tied (no one answers correct)
  46.  
  47. @trivia.DUELQUESTIME = 45
  48.  
  49. # Fraction of points lost during a duel (1/trivia.DUELFRAC)
  50.  
  51. @trivia.DUELFRAC = 3
  52.  
  53. # Minimum amount of points to participate in a duel
  54.  
  55. @trivia.DUELMIN = 5
  56.  
  57. # Minimum amount of seconds to wait before a person can duel again
  58.  
  59. @trivia.DUELREST = 30
  60.  
  61. # Number of seconds to pause between final score and start of wagering. Note that
  62. # the actual time between display of score and wagering start is WAGERWAIT - BREAK
  63. # since both timers are started at the same time.
  64.  
  65. @trivia.WAGERWAIT = 30
  66.  
  67. # Number of seconds to pause between start of wagering and end of wagering.
  68.  
  69. @trivia.WAGERTIME = 60
  70.  
  71. # Number of rounds available in one game, excluding wagering round.
  72.  
  73. @trivia.MAXROUND = 4
  74.  
  75. # Number of questions for each round. Last round must have exactly 1 question.
  76.  
  77. @trivia.QU.1 = 5
  78. @trivia.QU.2 = 5
  79. @trivia.QU.3 = 5
  80. @trivia.QU.4 = 5
  81. @trivia.QU.5 = 1
  82.  
  83. # Maximum number of daily double questions per round.
  84.  
  85. @trivia.SUDDENDEATH = 3
  86.  
  87. # Probability of daily double questions appearing (1/PROBDEATH).
  88.  
  89. @trivia.PROBDEATH = 8
  90.  
  91. # Proportion of regular round's point to take off if player gets daily double questions wrong.
  92. # The final penalty is (round's point)/trivia.PENALTYDEATH. Note that decimals are rounded down.
  93.  
  94. @trivia.PENALTYDEATH = 2
  95.  
  96. # Proportion of regular round's point to give to player if they get daily double questions right.
  97. # The final award is (round's point)*trivia.AWARDDEATH.
  98.  
  99. @trivia.AWARDDEATH = 2
  100.  
  101. # Amount of points awarded for each round. Last round is 0 points since it is the wagering
  102. # round, and people cannot obtain additional points for getting it right.
  103.  
  104. @trivia.P.1 = 2
  105. @trivia.P.2 = 4
  106. @trivia.P.3 = 6
  107. @trivia.P.4 = 8
  108. @trivia.P.5 = 0
  109.  
  110. # Amount of bonus point awarded for first person answering correctly.
  111.  
  112. @trivia.BONUSVALUE = 1
  113.  
  114. # Administrative password -- required for all admin commands.
  115.  
  116. @trivia.ADMINPASS = [default]
  117.  
  118. # Valid commands that can be sent to the bot.
  119.  
  120. @trivia.VALIDCMD = [!start !stop !reset !add !sub !load_s !load_q !wipe !save !duel !acc !ans !auth !unauth !change_pass !convert !title !title_kill]
  121.  
  122. # Valid admin commands that can be sent to the bot.
  123.  
  124. @trivia.VALIDADMINCMD = [!start !stop !reset !add !sub !load_s !load_q !wipe !save]
  125.  
  126. # Weight of penalty points. A weight of X would mean the player gets penalized WRONG/X at the
  127. # end of the game where WRONG is the number of wrong answers. Note that decimals are rounded down.
  128.  
  129. @trivia.PENALTYWEIGHT = 5
  130.  
  131. # Rank above which player can create their own title.
  132.  
  133. @trivia.MAXRANK = 1000
  134.  
  135. # People that cannot be duelled with. The nickname of the bot should be included here.
  136.  
  137. @trivia.NODUEL = [ChanServ TriviaBot]
  138.  
  139. # People who have helped on this project and deserves special mention.
  140.  
  141. @trivia.THANKYOU = [chibi_k, dunno001, Hisoka, InuTrunks, IPChan, Klepto, Knotz, lego, Mike-hime, melz, NFD, Teppei, XObadboy, xxloloxx]
  142.  
  143. # Version of the trivia script.
  144.  
  145. @trivia.VERSION = [1.1.0]
  146.  
  147. # --- PurePak Constants ---
  148.  
  149. @ PP.SET.RMCMD = [rm -f]
  150. @ PP.SAVEFILE = [trivia.sav]
  151. @ HOME = [:UserScripts]
  152.  
  153. # --- Channel Name ---
  154.  
  155. @trivia.channel = [Snak]
  156.  
  157. # --- Global Variables ---
  158.  
  159. # People who have answered the current question correctly
  160.  
  161. @trivia.curques = []
  162.  
  163. # Display variable for people who answered the current question correctly
  164.  
  165. @trivia.curqueslist = []
  166.  
  167. # Flag indicating whether a game is running (0:NO, 1:YES)
  168.  
  169. @trivia.current = 0
  170.  
  171. # Current trivia round number
  172.  
  173. @trivia.round = 0
  174.  
  175. # Questions remaining in current round
  176.  
  177. @trivia.remaining = 0
  178.  
  179. # Question number of current round being asked
  180.  
  181. @trivia.quesnum = 0
  182.  
  183. # Index for the encoding player score variables
  184.  
  185. @trivia.index = 0
  186.  
  187. # Flag indicating whether there is a question being shown right now
  188.  
  189. @trivia.active = 0
  190.  
  191. # A list of all used questions since the robot has been started
  192.  
  193. @trivia.usedques = []
  194.  
  195. # List of wrong answers submitted for current question
  196.  
  197. @trivia.wrong = []
  198.  
  199. # Flag indicating whether bonus points are given
  200.  
  201. @trivia.bonus = 0
  202.  
  203. # Flag indicating whether wagering is allowed
  204.  
  205. @trivia.wager = 0
  206.  
  207. # Flag to fix problems with the compare function during wagering
  208.  
  209. @trivia.wager_special = 0
  210.  
  211. # Count of the number of sudden death questions which has appeared
  212.  
  213. @trivia.amtdeath = 0
  214.  
  215. # Flag indicating whether current question is a sudden death question
  216.  
  217. @trivia.deathflag = 0
  218.  
  219. # Flag indicating whether the question list is loaded
  220.  
  221. @trivia.qloaded = 0
  222.  
  223. # Flag indicating whether there is a duel waiting to be accepted
  224.  
  225. @trivia.duelwait = 0
  226.  
  227. # Flag indicating that the duel victim has accepted the aggressor's challenge
  228.  
  229. @trivia.duelstart = 0
  230.  
  231. # Name of the duel aggressor
  232.  
  233. @trivia.duelagg = []
  234.  
  235. # Name of the duel victim
  236.  
  237. @trivia.duelvictim = []
  238.  
  239. # Players who answered the current duel question correctly
  240.  
  241. @trivia.duelrightlist = []
  242.  
  243. # A question timer to display how fast the players responds to the question
  244.  
  245. @trivia.timer = 0
  246.  
  247. # Players who are currently resting from a duel (i.e. cannot issue duel)
  248.  
  249. @trivia.duelrestlist = []
  250.  
  251. # --- Start of program code. Do not modify anything below this line. ---
  252.  
  253. alias trivia {
  254.     # Load the auxilary question file into memory if not loaded yet.
  255.  
  256.     if (!trivia.qloaded) {
  257.         $loadq()
  258.     }
  259.     
  260.     # Load the saved variables from file.
  261.     
  262.     if (!trivia.stat_loaded) {
  263.         /load $PP.SAVEFILE
  264.     }
  265.     
  266.     # Check whether we need to reset the score of the day, week, and month.
  267.     
  268.     @trivia.dummvar = update_high()
  269.     
  270.     # Check whether a game is currently running. Give an error if there is.
  271.  
  272.     if (trivia.current == 0) {
  273.         @trivia.current = 1
  274.         
  275.         # Print out the trivia header (copyright, thank you note, trivia record holder)
  276.         
  277.         ^say $trivia.channel Trivia v$trivia.VERSION Copyright 2002 by 5Seeker
  278.         ^say Special Thanks: $trivia.THANKYOU
  279.         ^say     
  280.         
  281.         if (!trivia.bestscore || trivia.bestscore == 0) {
  282.             ^say Highest Trivia Record:5 None @4 0 point
  283.         }
  284.         {
  285.             if (trivia.bestscore == 1) {
  286.                 ^say Highest Trivia Record:5 $trivia.bestname @4 1 point
  287.             }
  288.             {
  289.                 ^say Highest Trivia Record:5 $trivia.bestname @4 $trivia.bestscore points
  290.             }
  291.         }
  292.         
  293.         ^say     
  294.         
  295.         # Initialize the randomizer, clear global variables, and show the first question.
  296.         
  297.         @trivia.correct = 0
  298.         @trivia.round = 0
  299.         @trivia.remaining = 0
  300.         @trivia.quesnum = 0
  301.         @trivia.index = 0
  302.         @trivia.remaining = 0
  303.         @trivia.active = 0
  304.         @trivia.wager = 0
  305.         @trivia.wager_special = 0
  306.         @trivia.amtdeath = 0
  307.         @trivia.deathflag = 0
  308.         
  309.         @trivia.randomvar = trivia.randomvar + 1
  310.         @trivia.seed = [$time()] + trivia.randomvar
  311.         
  312.         $srand($trivia.seed)
  313.         $show_question()
  314.     }
  315.     {
  316.         ^say [ERROR] Please wait until the current game ends before starting another
  317.     }
  318. }
  319.  
  320. #     Load or reload the question into memory so it can be used by this script.
  321.  
  322. alias loadq {
  323.     ^load trivia_question
  324.     ^load trivia_taunt
  325. }
  326.  
  327. #     Show a question based on the round number. Higher rounds are more difficult. $0 controls whether the
  328. #     wagering round is on (0:NO, 1:YES).
  329.  
  330. alias show_question {
  331.     # Clear global variables.
  332.     
  333.     @trivia.curques = []
  334.     @trivia.curqueslist = []
  335.     @trivia.wrong = []
  336.  
  337.     # If no more questions available in this round, move to next round and reset question number.
  338.  
  339.     if (!trivia.remaining) {
  340.         @trivia.quesnum = 1
  341.         @trivia.round= trivia.round + 1
  342.         @trivia.remaining = trivia[QU][$trivia.round]
  343.     }
  344.     {
  345.         @trivia.quesnum = trivia.quesnum + 1
  346.     }
  347.     
  348.     # Set expiration timer for current question. If we are in wagering round, queue up $calc_wager to be called.
  349.     
  350.     if ([$0] == 1) {
  351.         ^timer -refnum 1 $trivia[LIMIT][$trivia.round] /calc_wager
  352.     }
  353.     {
  354.         ^timer -refnum 1 $trivia[LIMIT][$trivia.round] /stop
  355.     }
  356.  
  357.     # Find the maximum number of question available on the current difficulty level and choose
  358.     # one of them. If the question has been posed already, choose another one.
  359.  
  360.     @trivia.catques = trivia[C][$trivia.round]
  361.     @trivia.pick = rand($trivia.catques) + 1
  362.  
  363.     while ([$match($trivia.round*$trivia.pick $trivia.usedques)]) {
  364.         @trivia.pick = rand($trivia.catques) + 1
  365.     }
  366.  
  367.     # Add question to used question list (format round*quesnum)
  368.  
  369.     ^assign trivia.usedques $trivia.usedques $trivia.round*$trivia.pick
  370.     ^assign trivia.temp $trivia[A][$trivia.round][$trivia.pick]
  371.     ^assign trivia.temp $#trivia.temp
  372.  
  373.     # Potentially make this question a daily double question, but the wagering round cannot
  374.     # be turned into a daily double, so additional checks are done. If the question turns out
  375.     # to be a daily double, we increment $trivia.amtdeath by 1 to keep track.
  376.  
  377.     @trivia.deathflag = 0
  378.  
  379.     if ((trivia.amtdeath < trivia.SUDDENDEATH) && (trivia.round <= trivia.MAXROUND)) {
  380.         if (rand($trivia.PROBDEATH) == 0) {
  381.             @trivia.deathflag = 1
  382.             @trivia.amtdeath = trivia.amtdeath + 1
  383.         }
  384.     }
  385.  
  386.     if (!trivia.deathflag) {
  387.         ^say === Round $trivia.round Question $trivia.quesnum >> Time Limit: $trivia[LIMIT][$trivia.round] seconds ===
  388.     }
  389.     {
  390.         ^say === Round $trivia.round Question $trivia.quesnum >> Time Limit: $trivia[LIMIT][$trivia.round] seconds [DAILY DOUBLE] ===
  391.     }
  392.     
  393.     # If the answer is a number (i.e. trivia.Q.R.P.N is defined), don't print out the number of words
  394.     # so people are not confused.
  395.     
  396.     if (trivia[Q][$trivia.round][$trivia.pick][N]) {
  397.         ^say [4Q] 3$trivia[Q][$trivia.round][$trivia.pick] \<number\>
  398.     }
  399.     {
  400.         if (trivia.temp == 1) {
  401.             ^say [4Q] 3$trivia[Q][$trivia.round][$trivia.pick] \<$trivia.temp word\>
  402.         }
  403.         {
  404.             ^say [4Q] 3$trivia[Q][$trivia.round][$trivia.pick] \<$trivia.temp words\>
  405.         }
  406.     }
  407.     
  408.     # Start the timer so we can record down how fast the players answer the question. Also
  409.     # activate the trivia.active flag to indicate that there is an active question.
  410.     
  411.     @trivia.timer = time()
  412.     @trivia.active = 1
  413. }
  414.  
  415. #     Respond to trivia answers sent through private message. Calls $check_active() to see whether
  416. #     a question is currently being shown. $check_active() will also filter out commands and
  417. #     execute them.
  418.  
  419. on -msg "* *" {
  420.     $check_active($0 $1-)
  421. }
  422.  
  423. #     This function parses messages that the bot may receive. It processes both commands which begin
  424. #     with a "!" and regular answers. If there are no active question, all msgs are treated as regular
  425. #     text which is not processed (except commands, which are still processed).
  426.  
  427. alias check_active {
  428.     # Parsing of wagering messages.
  429.  
  430.     if (trivia.wager && word(0 $1-) == [!wager]) {
  431.         # Check to make sure there is a valid wager, meaning $2 exist and is a positive integer. We also
  432.         # check whether the player has enough points.
  433.         
  434.         @trivia.temp = strip(abcdefghijklmnopqrstuvwxyz. $tolower($2))
  435.         
  436.         if (!trivia.temp || trivia.temp <= 0 || trivia.temp > trivia[$encode($0)]) {
  437.             ^notice $0 [ERROR] Command is !wager <amount> where amount > 0 but < your score.
  438.         }
  439.         {
  440.             if (trivia.temp == 1) {
  441.                 ^notice $0 You have chosen to wager5 $trivia.temp point.
  442.             }
  443.             {
  444.                 ^notice $0 You have chosen to wager5 $trivia.temp points.
  445.             }
  446.             
  447.             # This is a validated wager, so go ahead and place it (exits function).
  448.             
  449.             $putwager($0 $trivia.temp)
  450.         }
  451.     }
  452.  
  453.     # Determine whether they are messaging a valid command. If so, go to command parsing.
  454.     # Otherwise, go to message parsing.
  455.  
  456.     if (match($word(0 $1-) $trivia.VALIDCMD)) {
  457.         $cmd_parse($0 $1-)
  458.     }
  459.     {
  460.         if (!trivia.active) {
  461.             # Normal private message, don't do anything.
  462.         }
  463.         {
  464.             # If it is the wagering round but they don't have points, they are not allowed to answer.
  465.                 
  466.             if ((trivia.round == (trivia.MAXROUND + 1)) && !trivia[$encode($0)]) {
  467.                 ^notice $0 [ERROR] You need at least 1 point to answer in the wagering round.
  468.             }
  469.             {
  470.                 # Check whether the submitted answer is a fun answer or a real answer. If it is just
  471.                 # a fun answer, a special routine is called to process it.
  472.                     
  473.                 if (word(0 $1-) == [!fun]) {
  474.                     $handle_fun($0 $2-)
  475.                 }
  476.                 {    
  477.                     $compare($0 $1-)
  478.                 }
  479.             }
  480.         }
  481.     }
  482. }
  483.  
  484. #     Handles commands embedded in the incoming private messages. If the command requires special
  485. #     authorization, this function checks the admin password before passing the command on to
  486. #     $parse_admin().
  487.  
  488. alias cmd_parse {
  489.     # !duel, !acc, and !duel_ans are used for the duelling system.
  490.     
  491.     if (word(0 $1-) == [!duel]) {
  492.         if (!word(1 $1-)) {
  493.             ^notice $0 [ERROR] Command is !duel <nick> where nick is the person you want to duel.
  494.         }
  495.         {
  496.             ^timer 1 /duel $0 $word(1 $1-)
  497.         }
  498.     }
  499.     
  500.     if (word(0 $1-) == [!acc]) {
  501.         ^timer 1 /accept_duel $0
  502.     }
  503.  
  504.     if (word(0 $1-) == [!ans]) {
  505.         if (!word(1 $1-)) {
  506.             ^notice $0 [ERROR] Command is !ans <ans> where ans is your answer.
  507.         }
  508.         {
  509.             ^timer 1 /duel_ans $0 $1-
  510.         }
  511.     }
  512.     
  513.     # !convert, !auth, !title, !title_kill, and !change_pass are used for the personal stat system.
  514.     
  515.     if (word(0 $1-) == [!convert]) {
  516.         if (!word(1 $1-) || !word(2 $1-)) {
  517.             ^notice $0 [ERROR] Command is !convert <old_nick> <password>.
  518.         }
  519.         {
  520.             ^timer 1 /check_conv $0 $word(1 $1-) $word(2 $1-)
  521.         }
  522.     }
  523.     
  524.     if (word(0 $1-) == [!auth]) {
  525.         if (!word(1 $1-)) {
  526.             ^notice $0 [ERROR] Command is !auth <password>.
  527.         }
  528.         {
  529.             ^timer 1 /check_auth $0 $word(1 $1-)
  530.         }
  531.     }
  532.  
  533.     if (word(0 $1-) == [!unauth]) {
  534.         ^timer 1 /deauth $0
  535.     }
  536.  
  537.     if (word(0 $1-) == [!change_pass]) {
  538.         if (!word(1 $1-) || !word(2 $1-)) {
  539.             ^notice $0 [ERROR] Command is !change_pass <old_pass> <new_pass>.
  540.         }
  541.         {
  542.             ^timer 1 /change_pass $0 $word(1 $1-) $word(2 $1-)
  543.         }
  544.     }
  545.     
  546.     if (word(0 $1-) == [!title]) {
  547.         @trivia.tempnet = trivia[RIGHT][$encode($0)] - trivia[WRONG][$encode($0)] / trivia.PENALTYWEIGHT
  548.         
  549.         if (trivia.tempnet < trivia.MAXRANK) {
  550.             ^notice $0 [ERROR] Sorry, but your rank is not high enough to use this command.
  551.         }
  552.         {
  553.             if (!word(1 $1-)) {
  554.                 ^notice $0 [ERROR] Command is !title <new title>.
  555.             }
  556.             {
  557.                 ^timer 1 /change_title $0 $2-
  558.             }
  559.         }
  560.     }
  561.  
  562.     if (word(0 $1-) == [!title_kill]) {
  563.         if (trivia[SELF_TITLE][$encode($0)] != []) {
  564.             ^assign -trivia[SELF_TITLE][$encode($0)]
  565.             ^notice $0 Your customized title has been successfully removed.
  566.         }
  567.         {
  568.             ^notice $0 [ERROR] Sorry, but you do not have a customized title to delete.
  569.         }
  570.     }
  571.  
  572.     # !start, !stop, !reset, !add, !sub, !load_s, !load_q, !wipe are admin cmds which require the
  573.     # admin password. Do not put non-admin commands below here becaues the admin password is
  574.     # checked at this point. Normal commands will fail.
  575.     
  576.     if (!match($word(0 $1-) $trivia.VALIDADMINCMD)) {
  577.         # Don't do anything since this is not an admin command.
  578.     }
  579.     {
  580.         if (word(1 $1-) != trivia.ADMINPASS) {
  581.             ^notice $0 [ERROR] The admin password you provided is not correct.
  582.         }
  583.         {
  584.             $parse_admin($0 $1-)
  585.         }
  586.     }
  587. }
  588.  
  589. #     Changes the title of an individual player. This function is assumed only accessible after a
  590. #     player achieves the minimum rank of trivia.MAXRANK.
  591.  
  592. alias change_title {
  593.     ^assign trivia[SELF_TITLE][$encode($0)] $1-
  594.     ^notice $0 Your title has been successfully changed.
  595. }
  596.  
  597. #     Handles the parsing of admin commands. This function assumes that when it is being called, the
  598. #     admin password has already been verified.
  599.  
  600. alias parse_admin {
  601.     if (word(0 $1-) == [!start]) {
  602.         ^timer 1 /trivia
  603.     }
  604.     
  605.     if (word(0 $1-) == [!stop]) {
  606.         /endtrivia
  607.     }
  608.  
  609.     if (word(0 $1-) == [!reset]) {
  610.         ^timer 1 /reset_used $0
  611.     }
  612.  
  613.     if (word(0 $1-) == [!wipe]) {
  614.         if (!word(2 $1-)) {
  615.             ^notice $0 [ERROR] Command is !wipe <nick>.
  616.         }
  617.         {
  618.             ^timer 1 /wipe_stat $0 $word(2 $1-)
  619.         }
  620.     }
  621.  
  622.     if (word(0 $1-) == [!save]) {
  623.         /sve
  624.         ^notice $0 The current game stats have been saved.
  625.     }
  626.  
  627.     if (word(0 $1-) == [!add]) {
  628.         if (!word(2 $1-) || !word(3 $1-)) {
  629.             ^notice $0 [ERROR] Command is !add <password> <nick> <amt>.
  630.         }
  631.         {
  632.             ^assign trivia.tempmsg $0
  633.             ^assign trivia.temppts $word(3 $1-)
  634.             ^userhost $word(2 $1-) -cmd ^assign trivia.tempadd $$0
  635.             ^userhost $word(2 $1-) -cmd if ([$3]){
  636.                 ^timer 1 /add_score $trivia.tempmsg $trivia.tempadd $trivia.temppts
  637.             }
  638.             {
  639.                 ^notice $trivia.tempmsg [ERROR] Player does not exist on the IRC server.
  640.             }
  641.         }
  642.     }
  643.     
  644.     if (word(0 $1-) == [!sub]) {
  645.         if (!word(2 $1-) || !word(3 $1-)) {
  646.             ^notice $0 [ERROR] Command is !sub <password> <nick> <amt>.
  647.         }
  648.         {
  649.             ^assign trivia.tempmsg $0
  650.              ^assign trivia.temppts $word(3 $1-)
  651.             ^userhost $word(2 $1-) -cmd ^assign trivia.tempadd $$0
  652.             ^userhost $word(2 $1-) -cmd if ([$3]){
  653.                 ^timer 1 /sub_score $trivia.tempmsg $trivia.tempadd $trivia.temppts
  654.             }
  655.             {
  656.                 ^notice $trivia.tempmsg [ERROR] Player does not exist on the IRC server.
  657.             }
  658.         }
  659.     }
  660.     
  661.     if (word(0 $1-) == [!load_s]) {
  662.         ^timer 1 /reload $0
  663.     }
  664.     
  665.     if (word(0 $1-) == [!load_q]) {
  666.         ^timer 1 /loadq
  667.     }
  668. }
  669.  
  670. #     Completely wipes a player's personal stat database. The first parameter is the person who invoked
  671. #     this function, and the second parameter is the nickname to wipe.
  672.  
  673. alias wipe_stat {
  674.     # Load the stat file if not loaded yet.
  675.     
  676.     if (!trivia.stat_loaded) {
  677.         /load $PP.SAVEFILE
  678.     }
  679.     
  680.     # Check to see if person being wiped exists
  681.     
  682.     if (!trivia[PASS][$encode($1)]) {
  683.         ^notice $0 [ERROR] The player you are trying to wipe does not exist.
  684.     }
  685.     {
  686.         # Don't let admins wipe stat during a game, or else weird things might happen.
  687.         
  688.         if (trivia.current) {
  689.             ^notice $0 [ERROR] You cannot use the !wipe command when a game is running.
  690.         }
  691.         {
  692.             ^assign -trivia[PASS][$encode($1)]
  693.             ^assign -trivia[RIGHT][$encode($1)]
  694.             ^assign -trivia[WRONG][$encode($1)]
  695.             ^assign -trivia[DUEL_WIN][$encode($1)]
  696.             ^assign -trivia[DUEL_LOSE][$encode($1)]
  697.             ^assign -trivia[GAME_WON][$encode($1)]
  698.             ^notice $0 $1's personal stat database has been successfully wiped.
  699.         }
  700.     }
  701. }
  702.  
  703. #     Handles humorous answer submission. Critera for a valid answer include player not having submitted
  704. #     a previous wrong answer. They are allowed to add a humorous answer even if they answered the question
  705. #     correct already.
  706.  
  707. alias handle_fun {
  708.     if (![$match($0 $trivia.wrong)] && ![$match($0, $trivia.wrong)]) {
  709.         $append_answer($0 $1-)
  710.         ^notice $0 Your fun answer has been added successfully.
  711.     }
  712.     {
  713.         ^notice $0 [ERROR] You have already submitted a fun or wrong answer.
  714.     }
  715. }
  716.  
  717. #     Reload the trivia script.
  718.  
  719. alias reload {
  720.     ^load trivia
  721.     ^notice $0 The trivia script has been successfully reloaded.
  722. }
  723.  
  724. #     Increase the score of player $1 by $2 points.
  725.  
  726. alias add_score {
  727.     @trivia.temp = [$2]
  728.  
  729.     if (trivia[$encode($1)]) {
  730.         @trivia[$encode($1)] = trivia[$encode($1)] + trivia.temp
  731.     }
  732.     {
  733.         @trivia[$encode($1)] = trivia.temp
  734.         @trivia.dummy = addtolist($1 0)
  735.     }
  736.     
  737.     ^notice $0 $1's score has been successfully changed.
  738. }
  739.  
  740. #     Decrease the score of player $0 by $1 points.
  741.  
  742. alias sub_score {
  743.     @trivia.temp = [$2]
  744.     @trivia[$encode($1)] = trivia[$encode($1)] - trivia.temp
  745.     
  746.     ^notice $0 $1's score has been successfully changed.
  747.     
  748. }
  749.  
  750. #     Place the wager for the player by assigning it to $trivia[$encode($0)][WAGER].
  751.  
  752. alias putwager {
  753.     @trivia[$encode($0)][WAGER] = [$1]
  754. }
  755.  
  756. #     Because the normal match procedure only matches one word, the match_all procedure is used
  757. #     to match all words. Based on whether this is a duel question, we either match against the
  758. #     normal answer or the duel answer (0: NORMAL, 1: DUEL).
  759.  
  760. alias match_all {
  761.     @trivia.counter = 0
  762.     @function_return = 1
  763.  
  764.     # Determine which answer to use
  765.     
  766.     if ([$0] == 0) {
  767.         @trivia.temp = trivia[A][$trivia.round][$trivia.pick]
  768.     }
  769.     {
  770.         @trivia.temp = trivia[A][$trivia.DUELLEVEL][$trivia.duelpick]
  771.     }
  772.     while (trivia.counter < [$#trivia.temp]) {
  773.         # Perform some generic pattern matching with pluaral and non-plural words.
  774.     
  775.         @trivia.tempword = word($trivia.counter $trivia.temp)
  776.  
  777.         if (right(1 $trivia.tempword) == [s] && right(3 $trivia.tempword) != [ies]) {
  778.             @trivia.tempword2 = left(${@trivia.tempword - 1} $trivia.tempword)
  779.            }
  780.         {
  781.             if (right(1 $trivia.tempword) == [y]) {
  782.                 @trivia.tempword2 = left(${@trivia.tempword - 1} $trivia.tempword)##[ies]
  783.             }
  784.                {
  785.                 if (right(3 $trivia.tempword) == [ies]) {
  786.                     @trivia.tempword2 = left(${@trivia.tempword - 3} $trivia.tempword)##[y]
  787.                 }
  788.                 {
  789.                        @trivia.tempword2 = trivia.tempword##[s]
  790.                 }
  791.             }
  792.         }
  793.         
  794.         # Perform some common typo matching between 'e' and 'i', 'l' and 'r', 'k' and 'c', 'j' and 'z', 'h' and 'u', 'o' and 'u'.
  795.         
  796.         @trivia.guessn1 = strip(ei $1-)
  797.         @trivia.guessn2 = strip(lr $1-)
  798.         @trivia.guessn3 = strip(kc $1-)
  799.         @trivia.guessn4 = strip(jz $1-)
  800.         @trivia.guessn5 = strip(hu $1-)
  801.         @trivia.guessn6 = strip(ou $1-)
  802.         
  803.         @trivia.ansn1 = strip(ei $trivia.tempword)
  804.         @trivia.ansn2 = strip(lr $trivia.tempword)
  805.         @trivia.ansn3 = strip(kc $trivia.tempword)
  806.         @trivia.ansn4 = strip(jz $trivia.tempword)
  807.         @trivia.ansn5 = strip(hu $trivia.tempword)
  808.         @trivia.ansn6 = strip(ou $trivia.tempword)
  809.         
  810.         if (![$match($trivia.tempword $1-)] && ![$match($trivia.tempword2 $1-)] && ![$match($trivia.ansn1 $trivia.guessn1)] && ![$match($trivia.ansn2 $trivia.guessn2)] && ![$match($trivia.ansn3 $trivia.guessn3)] && ![$match($trivia.ansn4 $trivia.guessn4)] && ![$match($trivia.ansn5 $trivia.guessn5)] && ![$match($trivia.ansn6 $trivia.guessn6)]) {
  811.             @function_return = 0
  812.         }
  813.         
  814.         @trivia.counter = trivia.counter + 1
  815.     }
  816. }
  817.  
  818. #     Display the bonus message when players get a question correct first. Sudden death questions
  819. #     give a certain multiple of the normal points.
  820.  
  821. alias display_bonus {
  822.     @function_return = 1
  823.  
  824.     if (trivia.deathflag) {
  825.         @trivia.temp = trivia.AWARDDEATH * trivia.BONUSVALUE
  826.         ^notice $0 For getting it correct first, you get5 $trivia.temp extra bonus points.
  827.     }
  828.     {
  829.         if (trivia.BONUSVALUE == 1) {
  830.             ^notice $0 For getting it correct first, you get5 $trivia.BONUSVALUE extra bonus point
  831.         }
  832.         {
  833.             ^notice $0 For getting it correct first, you get5 $trivia.BONUSVALUE extra bonus points
  834.         }
  835.     }
  836. }
  837.  
  838. #      Add the player to the list of participants. $1 denotes whether to initialized the player's
  839. #     score to 0 (0:NO, 1:YES).
  840.  
  841. alias addtolist {
  842.     @function_return = 1
  843.     @trivia[rec][$trivia.index] = encode($0)
  844.     @trivia.index = trivia.index + 1
  845.     @trivia[$encode($0)][LIST] = 1
  846.     
  847.     if ([$1] == 1) {
  848.         @trivia[$encode($0)] = 0
  849.     }
  850. }
  851.  
  852. #     Calculate the amount of points awarded to a player. $0 denotes whether a bonus value should
  853. #     be added during the computation (0:NO, 1:YES).
  854.  
  855. alias calcpoint {
  856.     if ([$0] == 1) {
  857.         @function_return = trivia[P][$trivia.round] + trivia.BONUSVALUE
  858.     }
  859.     {
  860.         @function_return = trivia[P][$trivia.round]
  861.     }
  862. }
  863.  
  864. #     Displays the timer on the correct answer list.
  865.  
  866. alias timer_display {
  867.     @function_return = 1
  868.     @trivia.temptime = time() - trivia.timer
  869.         
  870.     if (!trivia.curqueslist) {
  871.         ^assign trivia.curqueslist $0 5\[$trivia.temptime sec\]
  872.     }
  873.     {
  874.         ^assign trivia.curqueslist $trivia.curqueslist, $0 5\[$trivia.temptime sec\]
  875.     }
  876. }
  877.  
  878. #     Given the question number, this compares the inputted answer with the correct answer
  879. #     using pattern matching. This function also performs score keeping.
  880.  
  881. alias compare {
  882.     @trivia.bonus = 0
  883.     @trivia.finalscore = 0
  884.     @trivia.correct = match_all(0 $1-)
  885.  
  886.     # If correct answer and they have not answered already.
  887.  
  888.     if (trivia.correct && ![$match($0 $trivia.curques)]) {
  889.     
  890.         @trivia.dummvar = auth_help($0 0)
  891.         ^notice $0 You answered the question correctly. Congratulations!
  892.         
  893.         # First person to answer the question correct gets 1 bonus point, but only when it's not in the
  894.         # wagering round. If we are in sudden death round, we display twice the normal bonus point.
  895.         
  896.         if (!trivia.curques) {
  897.             if (!trivia.wager_special) {
  898.                 @trivia.bonus = 1
  899.                 @trivia.dummy = display_bonus($0)
  900.             }
  901.         }
  902.         
  903.         # Assign person to people who have already answered the current question correctly.
  904.         
  905.         ^assign trivia.curques $trivia.curques $0
  906.         
  907.         # Add person to the list to print out containing people who answered question correctly.
  908.         
  909.         @trivia.dummvar = timer_display($0)
  910.     
  911.         # Initiate a personal score variable. We must encode the text since some of the
  912.         # characters in a nickname cannot be part of a variable. If the variable already exists
  913.         # then add the scores on. We also add the encoded text to a global list so we can remove
  914.         # all the variables in the end.
  915.  
  916.         ^assign trivia.finalscore $calcpoint($trivia.bonus)
  917.         
  918.         # If the question is sudden death, increase the score the player receive, include the bonus
  919.         # points incurred.
  920.         
  921.         if (trivia.deathflag) {
  922.             @trivia[$encode($0)] = trivia[$encode($0)] + trivia.AWARDDEATH * trivia.finalscore
  923.         }
  924.         {
  925.             @trivia[$encode($0)] = trivia[$encode($0)] + trivia.finalscore
  926.         }
  927.  
  928.         if (!trivia[$encode($0)][LIST])
  929.         {
  930.             @trivia.dummy = addtolist($0 0)
  931.         }
  932.  
  933.         # We know they are added on the $trivia[rec] list at this point. Know we check whether they
  934.         # got the answer correct by submitting multiple answers on one line.
  935.         
  936.         @trivia.temp1 = [$1-]
  937.         @trivia.temp2 = trivia[A][$trivia.round][$trivia.pick]
  938.         @trivia.temp1 = [$#trivia.temp1]
  939.         @trivia.temp2 = [$#trivia.temp2]
  940.         
  941.         if (trivia.deathflag) {
  942.             if (trivia.temp1 > trivia.temp2) {
  943.                 # Multiplication by trivia.PENALTYWEIGHT since each penalty point is worth X number
  944.                 # of wrong answers where X = trivia.PENALTYWEIGHT.
  945.                 
  946.                 @trivia.penalty = trivia.PENALTYWEIGHT*trivia[P][$trivia.round]/trivia.PENALTYDEATH
  947.                 @trivia[$encode($0)][WRONG] = trivia[$encode($0)][WRONG] + trivia.penalty
  948.                 @trivia.dummvar = auth_help($0 4 $trivia.penalty)
  949.             }
  950.         }
  951.         {
  952.             if (trivia.temp1 > trivia.temp2) {
  953.                 @trivia.penalty = trivia.temp1/trivia.temp2 - 1
  954.                 @trivia[$encode($0)][WRONG] = trivia[$encode($0)][WRONG] + trivia.penalty
  955.                 @trivia.dummvar = auth_help($0 4 $trivia.penalty)
  956.             }
  957.         }
  958.     }
  959.     {
  960.         # If they answered the question already, or if the answer is incorrect.
  961.  
  962.         if ([$match($0 $trivia.curques)]) {
  963.             ^notice $0 [ERROR] You have already answered this trivia question!
  964.         }
  965.         {
  966.             # If the person has penalty point but is not on record, it's not good. Add them in so we
  967.             # can delete the variable in the end of the game.
  968.             
  969.             if (!trivia[$encode($0)][LIST]) {
  970.                 @trivia.dummy = addtolist($0 1)
  971.             }
  972.  
  973.             # Increment the number of wrong answers they've submitted. This is weighted by
  974.             # the length of the current answer to make the process fair. The assignments are done
  975.             # twice so the correct value can be stored.
  976.             
  977.             @trivia.temp1 = [$1-]
  978.             @trivia.temp2 = trivia[A][$trivia.round][$trivia.pick]
  979.             @trivia.temp1 = [$#trivia.temp1]
  980.             @trivia.temp2 = [$#trivia.temp2]
  981.             
  982.             # Multiplication by trivia.PENALTYWEIGHT since each penalty point is worth X number
  983.             # of wrong answers where X = trivia.PENALTYWEIGHT.
  984.             
  985.             if (trivia.deathflag) {
  986.                 @trivia.penalty = trivia.PENALTYWEIGHT*trivia[P][$trivia.round]/trivia.PENALTYDEATH
  987.             }
  988.             {
  989.                 @trivia.penalty = trivia.temp1/trivia.temp2
  990.             }
  991.             
  992.             @trivia[$encode($0)][WRONG] = trivia[$encode($0)][WRONG] + trivia.penalty
  993.             @trivia.dummvar = auth_help($0 4 $trivia.penalty)
  994.             
  995.             ^notice $0 Sorry, but your answer is not correct.
  996.             
  997.             # Add the wrong answer to a list so we can print it out, but only one per person.
  998.             
  999.             if (![$match($0 $trivia.wrong)]) {
  1000.                 $append_answer($0 $1-)
  1001.             }
  1002.         }
  1003.     }
  1004. }
  1005.  
  1006. #     Add a wrong answer to a $trivia.wrong so they can be printed out when the game ends.
  1007.  
  1008. alias append_answer {
  1009.     if (!trivia.wrong) {
  1010.         ^assign trivia.wrong $0 \[$1-\]
  1011.     }
  1012.     {
  1013.         ^assign trivia.wrong $trivia.wrong, $0 \[$1-\]
  1014.     }
  1015. }
  1016.  
  1017. #     Stops the current trivia challenge round and begin a new one after specified break time.
  1018.  
  1019. alias stop {
  1020.     ^say === Round $trivia.round Question $trivia.quesnum >> Time Limit Expired ===
  1021.     ^say The answer to this round was4 $toupper($trivia[A][$trivia.round][$trivia.pick]).
  1022.     
  1023.     if (!trivia.curques) {
  1024.         ^say Correct: <no one answered correctly>
  1025.     }
  1026.     {
  1027.         ^say Correct: $trivia.curqueslist
  1028.     }
  1029.     
  1030.     # If there are wrong answers available, print them out.
  1031.     
  1032.     if (trivia.wrong) {
  1033.         ^say Incorrect: $trivia.wrong
  1034.     }
  1035.     
  1036.     # Decrease the remaining question by one.
  1037.  
  1038.     @trivia.remaining = trivia.remaining - 1
  1039.  
  1040.     # If we are in final round and there is no more question, announce the final scores and go into
  1041.     # wagering mode. Otherwise set up a timer to show the next question.
  1042.  
  1043.     if ((trivia.round == trivia.MAXROUND) && (trivia.remaining == 0)) {
  1044.         ^timer -refnum 3 $trivia.BREAK /score
  1045.         ^timer -refnum 2 $trivia.WAGERWAIT /start_wager
  1046.         @trivia.active = 0
  1047.         $calc_penalty()
  1048.     }
  1049.     {
  1050.         ^timer -refnum 2 $trivia.BREAK /show_question
  1051.     }
  1052.  
  1053.     @trivia.active = 0
  1054. }
  1055.  
  1056. #     Calculate the penalty for each player by subtracting a fraction of the penalty points off their
  1057. #     total score.
  1058.  
  1059. alias calc_penalty {
  1060.     foreach trivia.rec ii {
  1061.         @trivia[$trivia[rec][$ii]] = trivia[$trivia[rec][$ii]] - (trivia[$trivia[rec][$ii]][WRONG]/trivia.PENALTYWEIGHT)
  1062.         
  1063.         # If score is less than 0, just keep it at 0.
  1064.         
  1065.         if (trivia[$trivia[rec][$ii]] < 0) {
  1066.             @trivia[$trivia[rec][$ii]] = 0
  1067.         }
  1068.     }
  1069. }
  1070.  
  1071. #     Start the wagering process by announcing the start of wagering and waiting $trivia.WAGERTIME.
  1072.  
  1073. alias start_wager {
  1074.     @trivia.wager = 1
  1075.     @trivia.round = trivia.MAXROUND + 1
  1076.     @trivia.remaining = 1
  1077.     @trivia.quesnum = 0
  1078.     
  1079.     ^say === Wagering Round For $trivia.channel Trivia ===
  1080.     ^say To wager,4 /msg $N !wager <amount> where amount is less than or equal to your total score.
  1081.     ^say You have4 $trivia.WAGERTIME seconds to place your wagers. You can also forfeit.
  1082.     
  1083.     ^timer -refnum 5 $trivia.WAGERTIME /stop_wager
  1084. }
  1085.  
  1086. #     Stops the wagering process by dropping the wager flag and showing the final question.
  1087.  
  1088. alias stop_wager {
  1089.     # Special form of $show_question causing the timer to call $calc_wager() when the timer expires
  1090.     # instead of the regular $stop().
  1091.     
  1092.     @trivia.wager = 0
  1093.     @trivia.wager_special = 1
  1094.     $show_question(1)
  1095. }
  1096.  
  1097. #     Clear out the used question list.
  1098.  
  1099. alias reset_used {
  1100.     @trivia.usedques = []
  1101.     ^notice $0 The used question list has been reset successfully.
  1102. }
  1103.  
  1104. #     Display the penalty points for each player. This function also lists out the number of
  1105. #     incorrect answers received from each player.
  1106.  
  1107. alias penalty {
  1108.     @trivia.temp = 0
  1109.  
  1110.     if (trivia.current) {
  1111.         ^say === Current Penalty Points ===
  1112.     }
  1113.     {
  1114.         ^say How you can expect to see penalties when there are no games going on?
  1115.     }
  1116.  
  1117.     if (trivia.index) {
  1118.         foreach trivia.rec ii {
  1119.             if (trivia[$trivia[rec][$ii]][WRONG]) {
  1120.                 @trivia.temp = 1
  1121.                 
  1122.                 ^assign trivia.temp2 ${trivia[$trivia[rec][$ii]][WRONG]/trivia.PENALTYWEIGHT}
  1123.             
  1124.                 if (trivia.temp2 <= 1 && trivia[$trivia[rec][$ii]][WRONG] <= 1) {
  1125.                     ^say $decode($trivia[rec][$ii]) --4 $trivia.temp2 point @4 $trivia[$trivia[rec][$ii]][WRONG] wrong answer
  1126.                 }
  1127.                 {
  1128.                     if (trivia.temp2 <= 1 && trivia[$trivia[rec][$ii]][WRONG] > 1) {
  1129.                         ^say $decode($trivia[rec][$ii]) --4 $trivia.temp2 point @4 $trivia[$trivia[rec][$ii]][WRONG] wrong answers
  1130.                     }
  1131.                     {
  1132.                         if (trivia.temp2 > 1 && trivia[$trivia[rec][$ii]][WRONG] <= 1) {
  1133.                             ^say $decode($trivia[rec][$ii]) --4 $trivia.temp2 points @4 $trivia[$trivia[rec][$ii]][WRONG] wrong answer
  1134.                         }
  1135.                         {    
  1136.                             ^say $decode($trivia[rec][$ii]) --4 $trivia.temp2 points @4 $trivia[$trivia[rec][$ii]][WRONG] wrong answers
  1137.                         }
  1138.                     }
  1139.                 }
  1140.             }
  1141.         }
  1142.         
  1143.         if (!trivia.temp) {
  1144.             if (trivia.current) {
  1145.                 ^say No one has been penalized so far.
  1146.             }
  1147.         }
  1148.     }
  1149.     {
  1150.         if (trivia.current) {
  1151.             ^say No one has been penalized so far.
  1152.         }
  1153.     }
  1154. }
  1155.  
  1156. #     Terminate the trivia program. ($0 == 1 means normal quit; $0 == 0 means abnormal)
  1157.  
  1158. alias endtrivia {
  1159.     @trivia.winnerscore = 0
  1160.  
  1161.     if (![$0]) {
  1162.         ^say Abnormal termination of $trivia.channel Trivia program.
  1163.         
  1164.         foreach trivia.rec ii {
  1165.             ^assign -trivia[$trivia[rec][$ii]][WAGER]
  1166.             ^assign -trivia[$trivia[rec][$ii]][WRONG]
  1167.             ^assign -trivia[$trivia[rec][$ii]][LIST]
  1168.             ^assign -trivia[$trivia[rec][$ii]]
  1169.             ^assign -trivia[rec][$ii]
  1170.         }
  1171.     }
  1172.     {
  1173.         # Clear out all player scores according to the global record list. Print out all
  1174.         # the scores, and delete the score variables.
  1175.         
  1176.         ^say === Final Results For $trivia.channel Trivia ===
  1177.         
  1178.         if (trivia.index) {
  1179.             foreach trivia.rec ii {
  1180.                 if (trivia[$trivia[rec][$ii]] == 0 || trivia[$trivia[rec][$ii]] == 1) {
  1181.                     ^say $decode($trivia[rec][$ii]) --4 $trivia[$trivia[rec][$ii]] point
  1182.                 }
  1183.                 {
  1184.                     ^say $decode($trivia[rec][$ii]) --4 $trivia[$trivia[rec][$ii]] points
  1185.                 }
  1186.                 
  1187.                 # Update the top trivia record if the old one has been broken
  1188.                 
  1189.                 if (trivia[$trivia[rec][$ii]] > trivia.bestscore) {
  1190.                     @trivia.bestscore = trivia[$trivia[rec][$ii]]
  1191.                     @trivia.bestname = decode($trivia[rec][$ii])
  1192.                 }
  1193.                 
  1194.                 # Update the top score of the day if the old one has been broken
  1195.                 
  1196.                 if (trivia[$trivia[rec][$ii]] > trivia.best_day_score) {
  1197.                     @trivia.best_day_score = trivia[$trivia[rec][$ii]]
  1198.                     @trivia.best_day_name = decode($trivia[rec][$ii])
  1199.                 }
  1200.                 
  1201.                 # Update the top score of the week if the old one has been broken
  1202.                 
  1203.                 if (trivia[$trivia[rec][$ii]] > trivia.best_week_score) {
  1204.                     @trivia.best_week_score = trivia[$trivia[rec][$ii]]
  1205.                     @trivia.best_week_name = decode($trivia[rec][$ii])
  1206.                 }
  1207.                 
  1208.                 # Update the top score of the month if the old one has been broken
  1209.                 
  1210.                 if (trivia[$trivia[rec][$ii]] > trivia.best_month_score) {
  1211.                     @trivia.best_month_score = trivia[$trivia[rec][$ii]]
  1212.                     @trivia.best_month_name = decode($trivia[rec][$ii])
  1213.                 }
  1214.                 
  1215.                 # Determine the top score of this game
  1216.                 
  1217.                 if (trivia[$trivia[rec][$ii]] > trivia.winnerscore) {
  1218.                     @trivia.winnerscore = trivia[$trivia[rec][$ii]]
  1219.                 }
  1220.             }
  1221.             
  1222.             # Now that we know the top score, we check everyone's score against top score
  1223.             # just in case there are ties. We award everyone with top score a game won record.
  1224.             
  1225.             foreach trivia.rec ii {
  1226.                 if (trivia[$trivia[rec][$ii]] == trivia.winnerscore) {
  1227.                     @trivia.dummvar = auth_help($decode($trivia[rec][$ii]) 3)
  1228.                 }
  1229.                 
  1230.                 ^assign -trivia[$trivia[rec][$ii]][WAGER]
  1231.                 ^assign -trivia[$trivia[rec][$ii]][WRONG]
  1232.                 ^assign -trivia[$trivia[rec][$ii]][LIST]
  1233.                 ^assign -trivia[$trivia[rec][$ii]]
  1234.                 ^assign -trivia[rec][$ii]
  1235.             }
  1236.         }
  1237.         {
  1238.             ^say No one managed to score any points during this game.
  1239.         }
  1240.     }
  1241.     
  1242.     # Clear out all the global variables and timers so weird things don't happen.
  1243.     
  1244.     if (trivia.active) {
  1245.         ^timer -delete 1
  1246.     }
  1247.     {
  1248.         ^timer -delete 2
  1249.     }
  1250.     
  1251.     @trivia.current = 0
  1252. }
  1253.  
  1254. #     Calculate the wager results based on what players wagered.
  1255.  
  1256. alias calc_wager {
  1257.     @trivia.active = 0
  1258.  
  1259.     ^say === Round $trivia.round Question $trivia.quesnum >> Time Limit Expired ===
  1260.     ^say The answer to this round was4 $toupper($trivia[A][$trivia.round][$trivia.pick]).
  1261.     
  1262.     if (!trivia.curques) {
  1263.         ^say Correct answers: <no one answered correctly>
  1264.     }
  1265.     {
  1266.         ^say Correct answers: $trivia.curqueslist
  1267.     }
  1268.     
  1269.     # If there are wrong answers available, print them out.
  1270.     
  1271.     if (trivia.wrong) {
  1272.         ^say Incorrect answers: $trivia.wrong
  1273.     }
  1274.     
  1275.     if (trivia.index) {
  1276.         foreach trivia.rec ii {
  1277.             if ([$trivia[$trivia[rec][$ii]]]) {
  1278.             
  1279.                 # If they got the wagering question correct, add the wager. Otherwise, subtract it.
  1280.                 
  1281.                 if (trivia[$trivia[rec][$ii]][WAGER]) {
  1282.                     if (match($decode($trivia[rec][$ii]) $trivia.curques)) {
  1283.                         @trivia[$trivia[rec][$ii]] = trivia[$trivia[rec][$ii]] + trivia[$trivia[rec][$ii]][WAGER]
  1284.                     }
  1285.                     {
  1286.                         @trivia[$trivia[rec][$ii]] = trivia[$trivia[rec][$ii]] - trivia[$trivia[rec][$ii]][WAGER]
  1287.                     }
  1288.                 }
  1289.             }
  1290.         }
  1291.     }
  1292.     
  1293.     $endtrivia(1)
  1294. }
  1295.  
  1296.  
  1297. #     Prints out the score of each player whose score is non-zero.
  1298.  
  1299. alias score {
  1300.     @trivia.temp = []
  1301.  
  1302.     if (trivia.current) {
  1303.         ^say === Current Scores ===
  1304.             
  1305.         if (trivia.index) {
  1306.             foreach trivia.rec ii {
  1307.                 if (match($decode($trivia[rec][$ii]) $trivia.temp)) {
  1308.                 }
  1309.                 {
  1310.                     if (trivia[$trivia[rec][$ii]] == 1 || trivia[$trivia[rec][$ii]] == 0) {
  1311.                         ^say $decode($trivia[rec][$ii]) --4 $trivia[$trivia[rec][$ii]] point
  1312.                     }
  1313.                     {
  1314.                         ^say $decode($trivia[rec][$ii]) --4 $trivia[$trivia[rec][$ii]] points
  1315.                     }
  1316.                     
  1317.                     ^assign trivia.temp $trivia.temp $decode($trivia[rec][$ii])
  1318.                 }
  1319.             }
  1320.         }
  1321.         {    
  1322.             ^say No one managed to score any points so far.
  1323.         }
  1324.     }
  1325.     {
  1326.         ^say How you can expect to see scores when there are no games going on?
  1327.     }
  1328. }
  1329.  
  1330. #     Function to handle dueling during games. This function is called when a !duel msg is
  1331. #     received by the bot.
  1332.  
  1333. alias duel {
  1334.     # Duels can only be started when there is a trivia game running, when a person has at least $trivia.DUELMIN
  1335.     # points, and when it's not the last round.
  1336.     
  1337.     if (!trivia.current || trivia[$encode($0)] < trivia.DUELMIN || ( ((trivia.round == trivia.MAXROUND) && (trivia.quesnum > 3)) || (trivia.round > trivia.MAXROUND) ) || trivia.duelwait || match($0 $trivia.duelagg) || match($0 $trivia.duelrestlist)) {
  1338.         if (!trivia.current) {
  1339.             ^notice $0 [ERROR] You cannot issue a duel when no game is going on.
  1340.         }
  1341.         {
  1342.             if (trivia[$encode($0)] < trivia.DUELMIN) {
  1343.                 ^notice $0 You need at least $trivia.DUELMIN points to start a duel.
  1344.             }
  1345.             {
  1346.                 if (( ((trivia.round == trivia.MAXROUND) && (trivia.quesnum > 3)) || (trivia.round > trivia.MAXROUND) )) {
  1347.                     ^notice $0 It is too late in the game to start a duel. Try earlier next time.
  1348.                 }
  1349.                 {
  1350.                     if (trivia.duelwait) {
  1351.                         ^notice $0 There is another duel going on right now. Please try later.
  1352.                     }
  1353.                     {
  1354.                         @trivia.temp1 = strip(\~\!\@\#\$\^\&\*\_\+\-\=\[\]\{\}\\\|\;\'\,\.\/\<\>\?\:\"\(\)\% $0)
  1355.                         @trivia.temp2 = strip(\~\!\@\#\$\^\&\*\_\+\-\=\[\]\{\}\\\|\;\'\,\.\/\<\>\?\:\"\(\)\% $trivia.duelagg)
  1356.                     
  1357.                         if (match($trivia.temp1 $trivia.temp2)) {
  1358.                             ^notice $0 You cannot initiate two duels at the same time!
  1359.                         }
  1360.                         {
  1361.                             ^notice $0 You have to wait $trivia.DUELREST seconds before you can duel again.
  1362.                         }
  1363.                     }
  1364.                 }
  1365.             }
  1366.         }
  1367.     }
  1368.     {
  1369.         # A person cannot duel with him/herself
  1370.     
  1371.         if (match($0 $1)) {
  1372.             ^say [DUEL] $0 pokes him or herself in the eye with a blazing hot iron bar.
  1373.         }
  1374.         {
  1375.             ^assign trivia.0 $0
  1376.             ^assign trivia.1 $1
  1377.             
  1378.             ^userhost $trivia.1 -cmd ^assign trivia.duelvictim $$0
  1379.             ^userhost $trivia.1 -cmd if ([$3]) {
  1380.         
  1381.                 # Certain people like ChanServ cannot be duelled with
  1382.         
  1383.                 if (match($trivia.duelvictim $trivia.NODUEL)) {
  1384.                     ^notice $trivia.0 [ERROR] You cannot issue a duel to that person.
  1385.                 }
  1386.                 {
  1387.                     # Cannot duel someone with less than $trivia.DUELMIN points
  1388.                     
  1389.                     if (trivia[$encode($trivia.duelvictim)] < trivia.DUELMIN) {
  1390.                         ^notice $trivia.0 You can only duel someone with at least $trivia.DUELMIN points.
  1391.                     }
  1392.                     {
  1393.                         @trivia.taunttemp = rand($trivia.TMAX) + 1                
  1394.                         ^say [DUEL] $trivia.0 yells at $trivia.duelvictim, "$trivia[T][$trivia.taunttemp]"
  1395.                     
  1396.                         @trivia.duelwait = 1
  1397.                         ^assign trivia.duelagg $trivia.0
  1398.                         ^timer -refnum 32 $trivia.DUELSTOPTIME /duelstop
  1399.                         ^notice $trivia.duelvictim $trivia.0 wants to duel with you. Accept with /msg $N !acc (no period).
  1400.                     }
  1401.                 }
  1402.             }
  1403.             {
  1404.                 # The requested person to duel with does not exist in the channel
  1405.         
  1406.                 ^say [DUEL] $trivia.0 kicks and screams at the wall.
  1407.             }
  1408.         }
  1409.     }
  1410. }
  1411.  
  1412. #     Function to handle the acceptance of a duel.
  1413.  
  1414. alias accept_duel {
  1415.     if (!trivia.duelvictim) {
  1416.         ^notice $0 There are no duels going on at this moment.
  1417.     }
  1418.     {
  1419.         if (!match($0 $trivia.duelvictim)) {
  1420.             ^notice $0 Trying to accept another person's duel for them is very unethical.
  1421.         }
  1422.         {
  1423.             if (trivia.duelstart) {
  1424.                 ^notice [ERROR] $0 But you have already accepted the duel!
  1425.             }
  1426.             {
  1427.                 ^say [DUEL] $trivia.duelvictim shouts back, "$trivia[R][$trivia.taunttemp]"
  1428.                 
  1429.                 # Set a special flag so the $duelstop() function will not terminate the duel
  1430.                 
  1431.                 @trivia.duelstart = 1
  1432.                 ^timer -refnum 31 5 /duelques
  1433.             }
  1434.         }
  1435.     }
  1436. }
  1437.  
  1438. #     Issues the duelling question to both the aggressor and the victim. We choose a question that
  1439. #     corresponds to $trivia.DUELLEVEL.
  1440.  
  1441. alias duelques {
  1442.     # Set expiration timer for duel question.
  1443.  
  1444.     ^timer -refnum 30 $trivia.DUELQUESTIME /duel_result
  1445.  
  1446.     # Find the maximum number of question available on the current difficulty level and choose
  1447.     # one of them. If the question has been posed already, choose another one.
  1448.  
  1449.     @trivia.duelcatques = trivia[C][$trivia.DUELLEVEL]
  1450.     @trivia.duelpick = rand($trivia.duelcatques) + 1
  1451.  
  1452.     while ([$match($trivia.DUELLEVEL*$trivia.duelpick $trivia.usedques)]) {
  1453.         @trivia.duelpick = rand($trivia.duelcatques) + 1
  1454.     }
  1455.  
  1456.     # Add question to used question list.
  1457.  
  1458.     ^assign trivia.usedques $trivia.usedques $trivia.DUELLEVEL*$trivia.duelpick
  1459.     ^assign trivia.temp $trivia[A][$trivia.DUELLEVEL][$trivia.duelpick]
  1460.     ^assign trivia.temp $#trivia.temp
  1461.     
  1462.     if (trivia.temp == 1) {
  1463.         ^notice $trivia.duelagg [DUEL Q] $trivia[Q][$trivia.DUELLEVEL][$trivia.duelpick] \<$trivia.temp word\>
  1464.         ^notice $trivia.duelvictim [DUEL Q] $trivia[Q][$trivia.DUELLEVEL][$trivia.duelpick] \<$trivia.temp word\>
  1465.     }
  1466.     {
  1467.         ^notice $trivia.duelagg [DUEL Q] $trivia[Q][$trivia.DUELLEVEL][$trivia.duelpick] \<$trivia.temp words\>
  1468.         ^notice $trivia.duelvictim [DUEL Q] $trivia[Q][$trivia.DUELLEVEL][$trivia.duelpick] \<$trivia.temp words\>
  1469.     }
  1470. }
  1471.  
  1472. #     Function to read in the duel answers and process them. For a duel, the first person to answer
  1473. #     correctly wins the duel, but we wait until $duel_result() is called to process the final winner
  1474. #     so we don't end up with concurrency issues in having multiple duels going on.
  1475.  
  1476. alias duel_ans {
  1477.     if (!trivia.duelvictim) {
  1478.         ^notice $0 There are no duels going on at this moment.
  1479.     }
  1480.     {
  1481.         if (!match($0 $trivia.duelagg) && !match($0 $trivia.duelvictim)) {
  1482.             ^notice $0 You are not participating in the current duel.
  1483.         }
  1484.         {    
  1485.             if (match($0 $trivia.duelrightlist)) {
  1486.                 ^notice $0 You have already answered the duel challenge correctly!
  1487.             }
  1488.             {
  1489.                 @trivia.duelcorrect = match_all(1 $1-)
  1490.             
  1491.                 if (trivia.duelcorrect) {
  1492.                     ^notice $0 Correct answer for duel -- seeing who answered first...
  1493.                     ^assign trivia.duelrightlist $trivia.duelrightlist $0
  1494.                 }
  1495.                 {
  1496.                     ^notice $0 Sorry, but your answer for the duel challenge is incorrect.
  1497.                 }
  1498.             }
  1499.         }
  1500.     }
  1501. }
  1502.  
  1503. #     Checks the result of a duel and redistributes points accordingly. This function calls $duel_award()
  1504. #     to distribute to the points.
  1505.  
  1506. alias duel_result {
  1507.  
  1508.     if (!trivia.duelrightlist) {
  1509.         ^say [DUEL] Neither person got the duel question correct. This duel ends in a draw.
  1510.     }
  1511.     {
  1512.         # Find the winner and loser, then send them as parameters into a point changer
  1513.         
  1514.         if (match($word(0 $trivia.duelrightlist) $trivia.duelagg)) {
  1515.             ^timer -refnum 34 1 /duel_award $trivia.duelagg $trivia.duelvictim
  1516.         }
  1517.         {
  1518.             ^timer -refnum 34 1 /duel_award $trivia.duelvictim $trivia.duelagg
  1519.         }
  1520.     }
  1521.  
  1522.     # Add both the aggressor and the victim to the resting list so they cannot start another duel right away
  1523.     
  1524.     ^assign trivia.duelrestlist $trivia.duelagg $trivia.duelvictim
  1525.     ^timer -refnum 33 $trivia.DUELREST /duel_rest_reset
  1526.  
  1527.     @trivia.duelwait = 0
  1528.     @trivia.duelcorrect = 0
  1529.     @trivia.duelstart = 0
  1530.     @trivia.duelrightlist = []
  1531.     @trivia.duelvictim = []
  1532.     @trivia.duelagg = []
  1533. }
  1534.  
  1535. #     Resets the duel resting list so the victim and aggressor and initiate a duel again.
  1536.  
  1537. alias duel_rest_reset {
  1538.     @trivia.duelrestlist = []
  1539. }
  1540.  
  1541. #     This function awards the winner of the duel challenge a certain percentage of the loser's scores.
  1542. #     The first parameter is the winner and the second is the loser.
  1543.  
  1544. alias duel_award {
  1545.     @trivia.tempaward = trivia[$encode($1)] / trivia.DUELFRAC
  1546.     @trivia[$encode($0)] = trivia[$encode($0)] + trivia.tempaward
  1547.     @trivia[$encode($1)] = trivia[$encode($1)] - trivia.tempaward
  1548.     
  1549.     if (trivia.tempaward == 1) {
  1550.         ^say [DUEL] $0 has plundered4 $trivia.tempaward point from $1.
  1551.     }
  1552.     {
  1553.         ^say [DUEL] $0 has plundered4 $trivia.tempaward points from $1.
  1554.     }
  1555.     
  1556.     @trivia.dummvar = auth_help($0 1)
  1557.     @trivia.dummvar = auth_help($1 2)
  1558. }
  1559.  
  1560. #     Stops a duel if the duel victim does not respond in a limited amount of time. This function
  1561. #     will not perform its duty if $trivia.duelstart is set.
  1562.  
  1563. alias duelstop {
  1564.     if (!trivia.duelstart) {
  1565.         ^say [DUEL] $trivia.duelvictim did not respond to $trivia.duelagg's duel request.
  1566.         @trivia.duelwait = 0
  1567.         @trivia.duelvictim = []
  1568.         @trivia.duelagg = []
  1569.     }
  1570.     
  1571.     @trivia.duelstart = 0
  1572. }
  1573.  
  1574. #     Authorizes a player to modify their own personal stat database.
  1575.  
  1576. alias check_auth {
  1577.     if (!trivia.stat_loaded) {
  1578.         /load $PP.SAVEFILE
  1579.     }
  1580.  
  1581.     if (trivia[AUTH][$encode($0)]) {
  1582.         ^notice $0 You have already been authenticated.
  1583.     }
  1584.     {
  1585.         if (trivia[PASS][$encode($0)] == [$1-]) {
  1586.             @trivia[AUTH][$encode($0)] = 1
  1587.             ^notice $0 You have been successfully authenticated!
  1588.         }
  1589.         {
  1590.             if (!trivia[PASS][$encode($0)]) {
  1591.                 ^notice $0 [ERROR] Sorry, but there are no records of you in the database.
  1592.             }
  1593.             {
  1594.                 ^notice $0 [ERROR] That is not the correct password. Please try again.
  1595.             }
  1596.         }
  1597.     }
  1598. }
  1599.  
  1600. #     Deauthorizes a player from modifying their own personal stat database.
  1601.  
  1602. alias deauth {
  1603.     if (!trivia[AUTH][$encode($0)]) {
  1604.         ^notice $0 [ERROR] You have not been authenticated!
  1605.     }
  1606.     {
  1607.         ^assign -trivia[AUTH][$encode($0)]
  1608.         ^notice $0 Your authentication has been successfully removed.
  1609.     }
  1610. }
  1611.  
  1612. #     Lets a user changes their personal stat password. Passwords cannot be blank and cannot
  1613. #     contain characters which are not assignable.
  1614.  
  1615. alias change_pass {
  1616.     if (!trivia[PASS][$encode($0)]) {
  1617.         ^notice $0 [ERROR] You do not have an account in the database!
  1618.     }
  1619.     {
  1620.         if (trivia[PASS][$encode($0)] != [$1]) {
  1621.             ^notice $0 [ERROR] The old password is incorrect. Please try again.
  1622.         }
  1623.         {
  1624.             if (strip(\~\!\@\#\$\^\&\*\_\+\-\=\[\]\{\}\\\|\;\'\,\.\/\<\>\?\:\"\(\)\% $2) != [$2]) {
  1625.                 ^notice $0 Your password may only contain alphanumerical choices.
  1626.             }
  1627.             {
  1628.                 @trivia[PASS][$encode($0)] = [$2]
  1629.                 ^notice $0 Your password has been changed successfully.
  1630.             }
  1631.         }
  1632.     }
  1633. }
  1634.  
  1635. #     Function to ask people for authorization when a change in their personal stat database is
  1636. #     required. The parameter $0 is the nickname of the person being authorized, and $1 is a
  1637. #     control variable that determines what stat to change (0: RIGHT, 1: DUEL_WIN, 2: DUEL_LOSE,
  1638. #     3: GAME_WON 4:WRONG).
  1639.  
  1640. alias auth_help {
  1641.     @function_return = 1
  1642.     
  1643.     if ([$1] == 0) {
  1644.         @trivia.type = [RIGHT]
  1645.     }
  1646.     {
  1647.         if ([$1] == 1) {
  1648.             @trivia.type = [DUEL_WIN]
  1649.         }
  1650.         {
  1651.             if ([$1] == 2) {
  1652.                 @trivia.type = [DUEL_LOSE]
  1653.             }
  1654.             {
  1655.                 if ([$1] == 3) {
  1656.                     @trivia.type = [GAME_WON]
  1657.                 }
  1658.                 {
  1659.                     if ([$1] == 4) {
  1660.                         @trivia.type = [WRONG]
  1661.                     }
  1662.                 }
  1663.             }
  1664.         }
  1665.     }
  1666.     
  1667.     # Check whether the person has authenticated with us. If not, keep track of regular game
  1668.     # score but do not modify the personal stat database to prevent fraud.
  1669.  
  1670.     if ((trivia[PASS][$encode($0)] != []) && !trivia[AUTH][$encode($0)]) {
  1671.         ^notice $0 Authenticate with /msg $N !auth <pass> to have stats updated.
  1672.     }
  1673.     {
  1674.         if (!trivia[PASS][$encode($0)]) {
  1675.             # Attach a random number to their nick as the starting password. No password
  1676.             # implies that this person is a new player, as passwords cannot be empty.
  1677.             
  1678.             @trivia.temp = rand(10000)
  1679.             @trivia.temp = [$0]##trivia.temp
  1680.         
  1681.             ^notice $0 New player with default password "$trivia.temp". Change it using /msg $N !change_pass <old pass> <new pass>.
  1682.             @trivia[AUTH][$encode($0)] = 1
  1683.             @trivia[PASS][$encode($0)] = trivia.temp
  1684.             @trivia[$trivia.type][$encode($0)] = 1
  1685.         }
  1686.         {
  1687.             if ([$1] != 4) {
  1688.                 @trivia[$trivia.type][$encode($0)] = trivia[$trivia.type][$encode($0)] + 1
  1689.             }
  1690.             {
  1691.                 @trivia[$trivia.type][$encode($0)] = trivia[$trivia.type][$encode($0)] + [$2]
  1692.             }
  1693.         }
  1694.     }
  1695. }
  1696.  
  1697. #     Checks to see whether $0 has any points. If so, we move all those points to $1 and delete
  1698. #     the original record. Otherwise, just ignore the event.
  1699.  
  1700. alias update_name {
  1701.  
  1702.     # Process nickname change only if they have score ≠ 0
  1703.     
  1704.     if (trivia[$encode($0)]) {
  1705.         # Transfer points over to new nick
  1706.         
  1707.         @trivia[$encode($1)] = trivia[$encode($0)]
  1708.         @trivia.dummy = addtolist($1 0)
  1709.         
  1710.         # Delete old nick so it's not displayed
  1711.         
  1712.         ^assign -trivia[$encode($0)][WAGER]
  1713.         ^assign -trivia[$encode($0)][WRONG]
  1714.         ^assign -trivia[$encode($0)][LIST]
  1715.         ^assign -trivia[$encode($0)]
  1716.         
  1717.         # Delete them from the record list also
  1718.         
  1719.         if (trivia.index) {
  1720.             foreach trivia.rec ii {
  1721.                 if (match($encode($0) $trivia[rec][$ii])) {
  1722.                     ^assign -trivia[rec][$ii]
  1723.                 }
  1724.             }
  1725.         }
  1726.     }
  1727. }
  1728.  
  1729. #     Converts a given amount of questions into an appropriate title
  1730.  
  1731. alias q_to_title {
  1732.     # If they have own title and rank is high enough, use that instead
  1733.     
  1734.     @trivia.tempnet = trivia[RIGHT][$encode($1)] - trivia[WRONG][$encode($1)] / trivia.PENALTYWEIGHT
  1735.     if (trivia[SELF_TITLE][$encode($1)] != [] && trivia.tempnet >= trivia.MAXRANK) {
  1736.         @function_return = [6$trivia[SELF_TITLE][$encode($1)]]
  1737.     }
  1738.     {
  1739.         if ([$0] < 0) { @function_return = [Court Jester] } {
  1740.         if ([$0] < 10) { @function_return = [Lowly Slime Mold] } {
  1741.         if ([$0] < 20) { @function_return = [Growing Slime Mold] } {
  1742.         if ([$0] < 30) { @function_return = [Regular Slime Mold] } {
  1743.         if ([$0] < 40) { @function_return = [Strong Slime Mold] } {
  1744.         if ([$0] < 50) { @function_return = [Slime Mold Master] } {
  1745.         if ([$0] < 60) { @function_return = [Smelly Fungus] } {
  1746.         if ([$0] < 70) { @function_return = [Fresh Fungus] } {
  1747.         if ([$0] < 80) { @function_return = [Kawaii Fungus] } {
  1748.         if ([$0] < 90) { @function_return = [Buffy Fungus] } {
  1749.         if ([$0] < 100) { @function_return = [Fungus Master] } {
  1750.         if ([$0] < 110) { @function_return = [Weak Peon] } {
  1751.         if ([$0] < 120) { @function_return = [Confused Peon] } {
  1752.         if ([$0] < 130) { @function_return = [Ordinary Peon] } {
  1753.         if ([$0] < 140) { @function_return = [Cheerful Peon] } {
  1754.         if ([$0] < 150) { @function_return = [Powerful Peon] } {
  1755.         if ([$0] < 160) { @function_return = [Poor Mercenary] } {
  1756.         if ([$0] < 170) { @function_return = [Lower Class Mercenary] } {
  1757.         if ([$0] < 180) { @function_return = [Middle Class Mercenary] } {
  1758.         if ([$0] < 190) { @function_return = [Upper Class Mercenary] } {
  1759.         if ([$0] < 200) { @function_return = [Mercenary Guildmaster] } {
  1760.             @function_return = q_to_title_2($0)
  1761.         }}}}}}}}}}}}}}}}}}}}}}
  1762. }
  1763.  
  1764. #     Converts a given amount of questions into an appropriate title
  1765.  
  1766. alias q_to_title_2 {
  1767.         if ([$0] < 210) { @function_return = [Apprentice Footman] } {
  1768.         if ([$0] < 220) { @function_return = [Advancing Footman] } {
  1769.         if ([$0] < 230) { @function_return = [Skilled Footman] } {
  1770.         if ([$0] < 240) { @function_return = [Advanced Footman] } {
  1771.         if ([$0] < 250) { @function_return = [Footman Squad Leader] } {
  1772.         if ([$0] < 260) { @function_return = [Unwieldly Thief] } {
  1773.         if ([$0] < 270) { @function_return = [Average Thief] } {
  1774.         if ([$0] < 280) { @function_return = [Skilled Thief] } {
  1775.         if ([$0] < 290) { @function_return = [Very Stealthy Thief] } {
  1776.         if ([$0] < 300) { @function_return = [Master Shadow Thief] } {
  1777.         if ([$0] < 310) { @function_return = [Weak Archer] } {
  1778.         if ([$0] < 320) { @function_return = [Copper Archer] } {
  1779.         if ([$0] < 330) { @function_return = [Silver Archer] } {
  1780.         if ([$0] < 340) { @function_return = [Gold Archer] } {
  1781.         if ([$0] < 350) { @function_return = [Platinum Archer] } {
  1782.         if ([$0] < 360) { @function_return = [Practicing Knight] } {
  1783.         if ([$0] < 370) { @function_return = [Trained Knight] } {
  1784.         if ([$0] < 380) { @function_return = [Skillful Knight] } {
  1785.         if ([$0] < 390) { @function_return = [Silver Knight] } {
  1786.         if ([$0] < 400) { @function_return = [Golden Knight] } {
  1787.             @function_return = [6God of Trivia]
  1788.     }}}}}}}}}}}}}}}}}}}}
  1789. }
  1790.  
  1791. #     Given a person's nickname, this function reports the number of correct answers
  1792. #     they've given.
  1793.  
  1794. alias report_stat {
  1795.     # Load the stat file if not loaded yet.
  1796.     
  1797.     if (!trivia.stat_loaded) {
  1798.         /load $PP.SAVEFILE
  1799.     }
  1800.  
  1801.     if (!trivia[PASS][$encode($0)]) {
  1802.         ^say There are no record of 5$0 in the database.
  1803.     }
  1804.     {
  1805.         # Calculate the "net" correct answer using RIGHT - WRONG/PENALTYWEIGHT
  1806.         @trivia.tempnet = trivia[RIGHT][$encode($0)] - trivia[WRONG][$encode($0)] / trivia.PENALTYWEIGHT
  1807.     
  1808.         if (trivia[GAME_WON][$encode($0)] > 25) {
  1809.             if (!trivia.tempnet) {
  1810.                 ^say \>\> Stats for Lord $0 the 2$q_to_title($trivia.tempnet $0) \(0\)
  1811.             }
  1812.             {        
  1813.                 ^say \>\> Stats for Lord $0 the 2$q_to_title($trivia.tempnet $0) \($trivia.tempnet\)
  1814.             }
  1815.         }
  1816.         {
  1817.             if (!trivia.tempnet) {
  1818.                 ^say \>\> Stats for $0 the 2$q_to_title($trivia.tempnet $0) \(0\)
  1819.             }
  1820.             {        
  1821.                 ^say \>\> Stats for $0 the 2$q_to_title($trivia.tempnet $0) \($trivia.tempnet\)
  1822.             }
  1823.         }
  1824.         
  1825.         @trivia.temp = [\>\> 4Duel: ]
  1826.         
  1827.         if (!trivia[DUEL_WIN][$encode($0)]) {
  1828.             @trivia.temp = trivia.temp##[0]
  1829.         }
  1830.         {
  1831.             @trivia.temp = trivia.temp##[$trivia[DUEL_WIN][$encode($0)]]
  1832.         }
  1833.         
  1834.         if (!trivia[DUEL_WIN][$encode($0)] || (trivia[DUEL_WIN][$encode($0)] == 1)) {
  1835.             @trivia.temp = trivia.temp##[ Win,]
  1836.         }
  1837.         {
  1838.             @trivia.temp = trivia.temp##[ Wins,]
  1839.         }
  1840.         
  1841.         if (!trivia[DUEL_LOSE][$encode($0)]) {
  1842.             @trivia.temp = trivia.temp##[ 0]
  1843.         }
  1844.         {
  1845.             @trivia.temp = trivia.temp##[ $trivia[DUEL_LOSE][$encode($0)]]
  1846.         }
  1847.         
  1848.         if (!trivia[DUEL_LOSE][$encode($0)] || (trivia[DUEL_LOSE][$encode($0)] == 1)) {
  1849.             @trivia.temp = trivia.temp##[ Loss     4Game: ]
  1850.         }
  1851.         {
  1852.             @trivia.temp = trivia.temp##[ Losses     4Game: ]
  1853.         }
  1854.         
  1855.         if (!trivia[GAME_WON][$encode($0)]) {
  1856.             @trivia.temp = trivia.temp##[0]
  1857.         }
  1858.         {
  1859.             @trivia.temp = trivia.temp##[$trivia[GAME_WON][$encode($0)]]
  1860.         }
  1861.         
  1862.         if (!trivia[GAME_WON][$encode($0)] || (trivia[GAME_WON][$encode($0)] == 1)) {
  1863.             @trivia.temp = trivia.temp##[ Domination]
  1864.         }
  1865.         {
  1866.             @trivia.temp = trivia.temp##[ Dominations]
  1867.         }
  1868.         
  1869.         ^say $trivia.temp
  1870.     }
  1871. }
  1872.  
  1873. #     Converts the personal data from one nickname to another nickname. $0 is the new nick,
  1874. #     $1 is the old nick, and $2 is the password.
  1875.  
  1876. alias check_conv {
  1877.     if (!trivia[PASS][$encode($1)]) {
  1878.         ^notice $0 [ERROR] Old personal stat information does not exist!
  1879.     }
  1880.     {
  1881.         if (trivia[PASS][$encode($1)] != [$2]) {
  1882.             ^notice $0 [ERROR] The password you supplied is incorrect. Please try again.
  1883.         }
  1884.         {
  1885.             if ([$0] == [$1]) {
  1886.                 ^notice $0 The personal stat information is already under your name!
  1887.             }
  1888.             {
  1889.                 if (trivia[PASS][$encode($0)]) {
  1890.                     ^notice $0 There is already a set of stat under $0 which cannot be overrided.
  1891.                 }
  1892.                 {
  1893.                     ^notice $0 Your personal stat information has been transferred into 5$0's authority.
  1894.                     
  1895.                     @trivia[PASS][$encode($0)] = trivia[PASS][$encode($1)]
  1896.                     ^assign -trivia[PASS][$encode($1)]
  1897.     
  1898.                     if (trivia[RIGHT][$encode($1)]) {
  1899.                         @trivia[RIGHT][$encode($0)] = trivia[RIGHT][$encode($1)]
  1900.                         ^assign -trivia[RIGHT][$encode($1)]
  1901.                     }
  1902.                     
  1903.                     if (trivia[DUEL_WIN][$encode($1)]) {
  1904.                         @trivia[DUEL_WIN][$encode($0)] = trivia[DUEL_WIN][$encode($1)]
  1905.                         ^assign -trivia[DUEL_WIN][$encode($1)]
  1906.                     }
  1907.                     
  1908.                     if (trivia[DUEL_LOSE][$encode($1)]) {
  1909.                         @trivia[DUEL_LOSE][$encode($0)] = trivia[DUEL_LOSE][$encode($1)]
  1910.                         ^assign -trivia[DUEL_LOSE][$encode($1)]
  1911.                     }
  1912.                     
  1913.                     if (trivia[WRONG][$encode($1)]) {
  1914.                         @trivia[WRONG][$encode($0)] = trivia[WRONG][$encode($1)]
  1915.                         ^assign -trivia[WRONG][$encode($1)]
  1916.                     }
  1917.                     if (trivia[GAME_WON][$encode($1)]) {
  1918.                         @trivia[GAME_WON][$encode($0)] = trivia[GAME_WON][$encode($1)]
  1919.                         ^assign -trivia[GAME_WON][$encode($1)]
  1920.                     }
  1921.                     
  1922.                     # Convert high score variables to new nickname too.
  1923.                     
  1924.                     if (trivia[bestname] == [$1]) {
  1925.                         @trivia[bestname] = [$0]
  1926.                     }
  1927.                     
  1928.                     if (trivia[best_day_name] == [$1]) {
  1929.                         @trivia[best_day_name] = [$0]
  1930.                     }
  1931.     
  1932.                     if (trivia[best_week_name] == [$1]) {
  1933.                         @trivia[best_week_name] = [$0]
  1934.                     }
  1935.                     
  1936.                     if (trivia[best_month_name] == [$1]) {
  1937.                         @trivia[best_month_name] = [$0]
  1938.                     }
  1939.                 }
  1940.             }
  1941.         }    
  1942.     }    
  1943. }
  1944.  
  1945. #     Resets the time stamp for the high score variables like score of the day, score of the
  1946. #     week, score of the month, score of the year. The $0 parameter determines which record to
  1947. #     reset (0:DAY 1:WEEK 2:MONTH).
  1948.  
  1949. alias time_reset {
  1950.     @function_return = 1
  1951.  
  1952.     if ([$0] == 0) {
  1953.         @trivia.timestamp_day = time()
  1954.         @trivia.best_day_name = [None]
  1955.         @trivia.best_day_score = 0
  1956.     }
  1957.     
  1958.     if ([$0] == 1) {
  1959.         @trivia.timestamp_week = time()
  1960.         @trivia.best_week_name = [None]
  1961.         @trivia.best_week_score = 0
  1962.     }
  1963.     
  1964.     if ([$0] == 2) {
  1965.         @trivia.timestamp_month = time()
  1966.         @trivia.best_month_name = [None]
  1967.         @trivia.best_month_score = 0
  1968.     }
  1969. }
  1970.  
  1971. #     Determines whether the high score variables need to be reset.
  1972.  
  1973. alias update_high {
  1974.     @function_return = 1
  1975.     @trivia.timecurr = time()
  1976.     
  1977.     # Reset score of the day after 24 hours
  1978.     
  1979.     if (trivia.timecurr - trivia.timestamp_day > 86400) {
  1980.         @trivia.dummvar = time_reset(0)
  1981.     }
  1982.     
  1983.     # Reset score of the week after 7 days
  1984.     
  1985.     if (trivia.timecurr - trivia.timestamp_week > 604800) {
  1986.         @trivia.dummvar = time_reset(1)
  1987.     }
  1988.     
  1989.     # Reset score of the month after 30 days
  1990.     
  1991.     if (trivia.timecurr - trivia.timestamp_month > 2592000) {
  1992.         @trivia.dummvar = time_reset(2)
  1993.     }
  1994. }
  1995.  
  1996. #     Reports the high score record for the day.
  1997.  
  1998. alias report_day {
  1999.     # Load the stat file if not loaded yet.
  2000.     
  2001.     if (!trivia.stat_loaded) {
  2002.         /load $PP.SAVEFILE
  2003.     }
  2004.  
  2005.     if (trivia.best_day_name == [None]) {
  2006.         ^say \>\> 4Daily High Score: <no record>
  2007.     }
  2008.     {
  2009.         @trivia.tempnet = trivia[RIGHT][$encode($trivia.best_day_name)] - trivia[WRONG][$encode($trivia.best_day_name)] / trivia.PENALTYWEIGHT
  2010.  
  2011.         ^say \>\> 4Daily High Score: $trivia.best_day_score by $trivia.best_day_name
  2012.     }
  2013. }
  2014.  
  2015. #     Reports the high score record for the week.
  2016.  
  2017. alias report_week {
  2018.     # Load the stat file if not loaded yet.
  2019.     
  2020.     if (!trivia.stat_loaded) {
  2021.         /load $PP.SAVEFILE
  2022.     }
  2023.  
  2024.     if (trivia.best_week_name == [None]) {
  2025.         ^say \>\> 4Weekly High Score: <no record>
  2026.     }
  2027.     {
  2028.         @trivia.tempnet = trivia[RIGHT][$encode($trivia.best_week_name)] - trivia[WRONG][$encode($trivia.best_week_name)] / trivia.PENALTYWEIGHT
  2029.  
  2030.         ^say \>\> 4Weekly High Score: $trivia.best_week_score by $trivia.best_week_name
  2031.     }
  2032. }
  2033.  
  2034. #     Reports the high score record for the month.
  2035.  
  2036. alias report_month {
  2037.     # Load the stat file if not loaded yet.
  2038.     
  2039.     if (!trivia.stat_loaded) {
  2040.         /load $PP.SAVEFILE
  2041.     }
  2042.  
  2043.     if (trivia.best_month_name == [None]) {
  2044.         ^say \>\> 4Monthly High Score: <no record>
  2045.     }
  2046.     {
  2047.         @trivia.tempnet = trivia[RIGHT][$encode($trivia.best_month_name)] - trivia[WRONG][$encode($trivia.best_month_name)] / trivia.PENALTYWEIGHT
  2048.  
  2049.         ^say \>\> 4Monthly High Score: $trivia.best_month_score by $trivia.best_month_name
  2050.     }
  2051. }
  2052.  
  2053. #     Shutdown routine for the bot. This will save the critical variables and then quit IRC.
  2054.  
  2055. alias shutdown {
  2056.     /sve
  2057.     /quit
  2058. }
  2059.  
  2060. #     Save routine for storing various statistical variables for the trivia script. This
  2061. #     routine has been "stolen" from the PurePak script. Credit is hereby given.
  2062.  
  2063. alias sve {
  2064.     if (!(HOME))
  2065.     {
  2066.         exec -name rm $PP.SET.RMCMD $PP.SAVEFILE
  2067.         echo *** Warning: Your home directory could not be determined.  Your saved settings file will be saved to the current working directory.  If this isn't your home directory, PurePak may not be able to find it's saved settings file at startup!
  2068.     } {/exec -name rm $PP.SET.RMCMD ${HOME}/$PP.SAVEFILE}
  2069.     wait -CMD %rm if (1) {
  2070.         if (PP.EPIC)
  2071.         {
  2072.             if (!(HOME)) {@ FHANDLE = open($PP.SAVEFILE w)} {@ FHANDLE = open(${HOME}/$PP.SAVEFILE w)}
  2073.             if (FHANDLE > 0) {/EVAL ^assign WM /write $FHANDLE}
  2074.             {
  2075.                 echo *** Could not open target file!
  2076.                 @ WM = [/comment]
  2077.             }
  2078.         }
  2079.         {
  2080.             @ WM = [/xecho -WINDOW WRITEOUT]
  2081.             ^window new
  2082.             ^window log_extrainfo off
  2083.             ^window hold_mode off
  2084.             ^window name WRITEOUT
  2085.             if (!(HOME)) {^window logfile $PP.SAVEFILE} {^window logfile ${HOME}/$PP.SAVEFILE}
  2086.             ^window log on
  2087.         }
  2088.         $WM # Trivia version $trivia.VERSION saved settings file
  2089.         $WM # Written $stime($time())
  2090.         $WM          
  2091.         
  2092.         @trivia.dummvar = save_help($WM)
  2093.         
  2094.         $WM # Player personal stat passwords
  2095.         foreach trivia.PASS ii {
  2096.             $WM @ trivia[PASS][$ii] = [$trivia[PASS][$ii]]
  2097.         }
  2098.         $WM          
  2099.         $WM # Number of questions player got right
  2100.         foreach trivia.RIGHT ii {
  2101.             $WM @ trivia[RIGHT][$ii] = [$trivia[RIGHT][$ii]]
  2102.         }
  2103.         $WM          
  2104.         $WM # Number of questoins player got wrong
  2105.         foreach trivia.WRONG ii {
  2106.             $WM @ trivia[WRONG][$ii] = [$trivia[WRONG][$ii]]
  2107.         }
  2108.         $WM          
  2109.         $WM # Number of duels player won
  2110.         foreach trivia.DUEL_WIN ii {
  2111.             $WM @ trivia[DUEL_WIN][$ii] = [$trivia[DUEL_WIN][$ii]]
  2112.         }
  2113.         $WM          
  2114.         $WM # Number of duels player lost
  2115.         foreach trivia.DUEL_LOSE ii {
  2116.             $WM @ trivia[DUEL_LOSE][$ii] = [$trivia[DUEL_LOSE][$ii]]
  2117.         }
  2118.         $WM          
  2119.         $WM # Number of trivia games player won
  2120.         foreach trivia.GAME_WON ii {
  2121.             $WM @ trivia[GAME_WON][$ii] = [$trivia[GAME_WON][$ii]]
  2122.         }
  2123.         $WM          
  2124.         $WM # Customized titles for players
  2125.         foreach trivia.SELF_TITLE ii {
  2126.             $WM @ trivia[SELF_TITLE][$ii] = [$trivia[SELF_TITLE][$ii]]
  2127.         }
  2128.         $WM          
  2129.         $WM echo *** Saved settings loaded from ${PP.SAVEFILE}
  2130.         if (match(*xecho* $WM))
  2131.         {
  2132.             ^window log off
  2133.             ^window kill
  2134.         }
  2135.         {
  2136.             comment $close($FHANDLE)
  2137.             ^assign -FHANDLE
  2138.         }
  2139.         ^assign -WM
  2140.         echo *** Current settings saved to ${PP.SAVEFILE}
  2141.     }
  2142. }
  2143.  
  2144. #     Help function of the save alias.
  2145.  
  2146. alias save_help {
  2147.     $0 # Flag to indicate loading of stat file
  2148.     $0 @ trivia[stat_loaded] = [1]
  2149.     $0          
  2150.     $0 # Random seeding value
  2151.     $0 @ trivia[randomvar] = [$trivia[randomvar]]
  2152.     $0          
  2153.     $0 # Top trivia score holder
  2154.     $0 @ trivia[bestname] = [$trivia[bestname]]
  2155.     $0 @ trivia[bestscore] = [$trivia[bestscore]]
  2156.     $0          
  2157.     $0 # Daily high score variables
  2158.     $0 @ trivia[timestamp_day] = [$trivia[timestamp_day]]
  2159.     $0 @ trivia[best_day_name] = [$trivia[best_day_name]]
  2160.     $0 @ trivia[best_day_score] = [$trivia[best_day_score]]
  2161.     $0        
  2162.     $0 # Weekly high score variables
  2163.     $0 @ trivia[timestamp_week] = [$trivia[timestamp_week]]
  2164.     $0 @ trivia[best_week_name] = [$trivia[best_week_name]]
  2165.     $0 @ trivia[best_week_score] = [$trivia[best_week_score]]
  2166.     $0        
  2167.     $0 # Monthly high score variables
  2168.     $0 @ trivia[timestamp_month] = [$trivia[timestamp_month]]
  2169.     $0 @ trivia[best_month_name] = [$trivia[best_month_name]]
  2170.     $0 @ trivia[best_month_score] = [$trivia[best_month_score]]
  2171.     $0        
  2172. }
  2173.  
  2174. #     Displays the current scores when people type in !trivia_score in the main channel.
  2175.  
  2176. on -public "* * !trivia score" {
  2177.     ^timer 1 /score
  2178. }
  2179.  
  2180. #     Displays the current penalty points.
  2181.  
  2182. on -public "* * !trivia penalty" {
  2183.     ^timer 1 /penalty
  2184. }
  2185.  
  2186. #     Start a new game of trivia
  2187.  
  2188. on -public "* * !trivia start" {
  2189.     ^timer 1 /trivia
  2190. }
  2191.  
  2192. #     Help system which private notices a help menu to people who type !help in the channel.
  2193.  
  2194. on -public "* * !help" {
  2195.     ^notice $0 Please type4 !help <topic> in the trivia channel to receive help:
  2196.     ^notice $0 01. General info: copyright, general, record, score, start_game, stat
  2197.     ^notice $0 02. Special features: daily_double, duel, fun, penalty
  2198.     ^notice $0 03. Stat related: auth, change_pass, convert, title, title_kill, unauth
  2199.     ^notice $0 04. Admin control: add, load_q, load_s, reset, save, start, stop, sub, wipe
  2200. }
  2201.  
  2202. # General information help system
  2203.  
  2204. on -public "* * !help copyright" {
  2205.     ^notice $0 The full content of this script as well auxilary support files are copyrights of Bernard Yen. You are allowed to modify and distribute the script on a non-profit basis, but changes must be clearly stated and not misrepresented as the original.
  2206. }
  2207.  
  2208. on -public "* * !help general" {
  2209.     ^notice $0 Welcome to $trivia.channel Trivia. There are $trivia.MAXROUND rounds every game, each consisting of $trivia.QU.1 questions, followed by a wagering round where you can potentially double your score. Points are allocated as $trivia.P.1, $trivia.P.2, $trivia.P.3, and $trivia.P.4 respectively for the $trivia.MAXROUND rounds. Approximately 2 questions per game are daily double questions that carry both greater award and penalty. To answer, simply /msg $N <answer> using your IRC client.
  2210. }
  2211.  
  2212. on -public "* * !help record" {
  2213.     ^notice $0 The record of your gameplay is kept in a personal stat database. This can be accessed by typing !stat <nick> in the channel where nick is case sensitive. In addition, you can access the high score of the day, week, and month by typing !trivia day, !trivia week, and !trivia month respectively into the trivia channel.
  2214. }
  2215.  
  2216. on -public "* * !help score" {
  2217.     ^notice $0 The current list of scores achieved by players can be viewed by typing !trivia score into the trivia channel. Penalties are not subtracted until right before the wagering round starts.
  2218. }
  2219.  
  2220. on -public "* * !help start_game" {
  2221.     ^notice $0 You can start a game of trivia at any time by typing !trivia start into the trivia channel, but please note that only an admin can stop the game while it is in progress.
  2222. }
  2223.  
  2224. on -public "* * !help stat" {
  2225.     ^notice $0 You can view any player's personal stat database by typing !stat <nick> into the trivia channel where nick is a case sensitive nickname.
  2226. }
  2227.  
  2228. # Special features help system
  2229.  
  2230. on -public "* * !help daily_double" {
  2231.     ^notice $0 Every game, there are approximately 2 questions that will have "daily double" after them. Getting those correct will give you double the normal points, but getting them incorrect will cause you to lose half of what the round is worth. If the round is normally worth 2 points, you could potentially gain 4 points or lose 2 points per guess.
  2232. }
  2233.  
  2234. on -public "* * !help duel" {
  2235.     ^notice $0 You can now challenge another person to a duel using /msg $N !duel <nick> and potentially plunder 30% of their points. Duelling is enabled when you have at least $trivia.DUELMIN points, the game isn't about to end, and there isn't another duel going on. To answer a duel, use /msg $N !ans <answer>. After a duel, you must wait $trivia.DUELREST seconds before you can start another one.
  2236. }
  2237.  
  2238. on -public "* * !help fun" {
  2239.     ^notice $0 You can now submit funny or plain wrong answers to show other players your creative juice without getting penalized. Simply message the bot with /msg $N !fun <answer> and it will be added.
  2240. }
  2241.  
  2242. on -public "* * !help penalty" {
  2243.     ^notice $0 To alleviate cheating and random guessing, incorrect answers are now penalized. Penalty is based on the length of your answer submission divided by the length of the actual answer. If the answer is "triviabot rules" and you type "triviabot is really stupid", you will get penalized (4/2) / $trivia.PENALTYWEIGHT = 0.4 points. At the end, penalty points are added and rounded down.
  2244. }
  2245.  
  2246. # Stat commands help system
  2247.  
  2248. on -public "* * !help auth" {
  2249.     ^notice $0 By typing /msg $N !auth <password> you unlock your personal stat database and allow changes to it. You must do this only when the bot first enters the channel or if you used the !unauth command earlier.
  2250. }
  2251.  
  2252. on -public "* * !help change_pass" {
  2253.     ^notice $0 By typing /msg $N !change_pass <old> <new> you can change your password from <old> to <new>.
  2254. }
  2255.  
  2256. on -public "* * !help convert" {
  2257.     ^notice $0 By typing /msg $N !convert <old_nick> <password> you can convert your personal stat database from the old nick and move it onto your current nick. This is handy if you have many different nicknames but want your stats to follow you.
  2258. }
  2259.  
  2260. on -public "* * !help title" {
  2261.     ^notice $0 By typing /msg $N !title <title> after you reach a rank of at least $trivia.MAXRANK, you will be able to create a customized title for your personal stat database display.
  2262. }
  2263.  
  2264. on -public "* * !help title_kill" {
  2265.     ^notice $0 By typing /msg $N !title_kill you can delete your customized title.
  2266. }
  2267.  
  2268. on -public "* * !help unauth" {
  2269.     ^notice $0 By typing /msg $N !unauth when you want to leave the channel, you lock your personal stat database and prevent further changes to it.
  2270. }
  2271.  
  2272. # Admin control help system
  2273.     #^notice $0 04. Admin commands: add, load_q, load_s, reset, save, start, stop, sub, wipe
  2274. on -public "* * !help add" {
  2275.     ^notice $0 By typing /msg $N !add <adm_pass> <nick> <pts> you can add points to a specified player.
  2276. }
  2277.  
  2278. on -public "* * !help load_q" {
  2279.     ^notice $0 By typing /msg $N !load_q <adm_pass> you can reload the question file. This is useful if you modified the question file while a game is running and want new questions to show up.
  2280. }
  2281.  
  2282. on -public "* * !help load_s" {
  2283.     ^notice $0 By typing /msg $N !load_s <adm_pass> you can reload the script file. Do not do this while a game is running or else weird things might happen.
  2284. }
  2285.  
  2286. on -public "* * !help reset" {
  2287.     ^notice $0 By typing /msg $N !reset <adm_pass> you can reset the used question list.
  2288. }
  2289.  
  2290. on -public "* * !help save" {
  2291.     ^notice $0 By typing /msg $N !save <adm_pass> you can save trivia variables to the file. Please note that this is currently buggy and may cause unexpected crashes.
  2292. }
  2293.  
  2294. on -public "* * !help start" {
  2295.     ^notice $0 By typing /msg $N !start <adm_pass> you can start a game of trivia.
  2296. }
  2297.  
  2298. on -public "* * !help stop" {
  2299.     ^notice $0 By typing /msg $N !stop <adm_pass> you can stop a game of trivia.
  2300. }
  2301.  
  2302. on -public "* * !help sub" {
  2303.     ^notice $0 By typing /msg $N !sub <adm_pass> <nick> <pts> you can subtract points from a specified player.
  2304. }
  2305.  
  2306. on -public "* * !help wipe" {
  2307.     ^notice $0 By typing /msg $N !wipe <adm_pass> <nick> where nick is a case sensitive nickname, you can wipe the personal stat database of the specified player.
  2308. }
  2309.  
  2310. #     Hook to detect changes in nickname so we can update the score database so the points
  2311. #     will move with the person.
  2312.  
  2313. on -channel_nick "* * *" {
  2314.     ^timer 1 /update_name $1 $2
  2315. }
  2316.  
  2317. #     Process trivia statistic queries.
  2318.  
  2319. on -public "* * !stat %" {
  2320.     ^timer 1 /report_stat $word(1 $2-)
  2321. }
  2322.  
  2323. on -public "* * !trivia day" {
  2324.     ^timer 1 /report_day
  2325. }
  2326.  
  2327. on -public "* * !trivia week" {
  2328.     ^timer 1 /report_week
  2329. }
  2330.  
  2331. on -public "* * !trivia month" {
  2332.     ^timer 1 /report_month
  2333. }